﻿using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.ServiceModel;

namespace WcfServiceWithUserNamePassword
{
    public class DistributorValidator : UserNamePasswordValidator
    {
        public override void Validate(string userName, string password)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
                throw new SecurityTokenException("Username and password required");

            var repository = new DistributorRepository();

            if (!repository.IsKnownDistributor(userName, password))
                throw new FaultException(string.Format("Wrong username ({0}) or password ", userName));
        }
    }

    public class DistributorRepository
    {
        public bool IsKnownDistributor(string userName, string password)
        {
            return userName.Equals("duc") && password.Equals("ducadmin");
        }
    }
}
